﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace RobotEscape.Entities
{
    public class Plate : EntityBase
    {
        public PlateColor PlateColor;
        public Color hudOnColor;
        public Color hudOffColor;
        private Level currentLevel;
        public bool _activated = false;
        public bool Activated
        {
            get
            {
                return _activated;
            }
            set
            {
                if (_activated != value && value == true)
                {
                    Sound.Play(Sounds.Click);
                }
                _activated = value;
                foreach (Exit exit in currentLevel.GameScreen.entities.OfType<Exit>())
                {
                    if (!exit.allOpen)
                    {
                        if (this.PlateColor == Entities.PlateColor.Blue)
                            exit.bClosed = !value;
                        if (this.PlateColor == Entities.PlateColor.Green)
                            exit.gClosed = !value;
                        if (this.PlateColor == Entities.PlateColor.Red)
                            exit.rClosed = !value;
                        if (this.PlateColor == Entities.PlateColor.Yellow)
                            exit.yClosed = !value;
                    }
                }

            }
        }

        public Plate(PlateColor _color, Level _currentLevel)
        {
            this.PlateColor = _color;
            currentLevel = _currentLevel;
            switch (_color)
            {
                case PlateColor.Red:
                    hudOffColor = Color.FromArgb(255, 80, 0, 0);
                    hudOnColor = Color.FromArgb(255, 255, 0, 0);
                    break;
                case PlateColor.Green:
                    hudOffColor = Color.FromArgb(255, 0, 80, 0);
                    hudOnColor = Color.FromArgb(255, 0, 255, 0);
                    break;
                case PlateColor.Blue:
                    hudOffColor = Color.FromArgb(255, 0, 0, 170);
                    hudOnColor = Color.FromArgb(255, 50, 50, 255);
                    break;
                case PlateColor.Yellow:
                    hudOffColor = Color.FromArgb(255, 123, 73, 2);
                    hudOnColor = Color.FromArgb(255, 203, 121, 3);
                    break;
            }
            width = 20;
            height = 20;
        }

        public override void Update(GameTime time)
        {
            bool newActivated = false;
            foreach (EntityBase entity in currentLevel.GameScreen.entities)
            {
                Player p = (entity as Player);
                if (p != null)
                {
                    if (p.CollidesWith(this))
                    {
                        newActivated = true;
                    }
                }
            }
            Activated = newActivated;
            base.Update(time);
        }

    }
    public enum PlateColor
    {
        Blue, Green, Red, Yellow
    }
}
